//
//  ViewController.m
//  午分享_UIPickView
//
//  Created by li cheng on 16/7/25.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDelegate, UIPickerViewDataSource>
@property (nonatomic, strong) NSArray *arr;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UIPickerView *pickView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 200)];
    pickView.backgroundColor = [UIColor redColor];
    pickView.delegate = self;
    pickView.dataSource = self;
    [self.view addSubview:pickView];
    _arr = @[@"大不大", @"中不中", @"小不小"];
    
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 2;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    return _arr.count;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
    label.text = [_arr objectAtIndex:row];
    [view1 addSubview:label];
    return view1;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
//    NSString * str = [_arr objectAtIndex:row];
//    NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:str];
//    attributed setValuesForKeysWithDictionary:@{}
    if (component == 0) {
        return @"辽宁";
    } else if (component == 1) {
        return @"大连";
    } else {
        return @"沙河口区";
    }
    // 这个地方貌似写没写没什么用
//    return [_arr objectAtIndex:row];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
